<template>
	<div class="add-style">
		<div>
			<label>{{$t('route.Basic_Management')}}</label>
			<div></div>
			<button><img /><label>{{ form.id ? $t('route.Edit_Style') : $t('route.Add_style') }}</label></button>
		</div>
		<div>
			<el-form size="medium" style="width: 50%;" label-width="100px">
				<el-form-item :label="$t('route.Picture')">
					<el-upload accept="image/*" :action="uploadUrl" :show-file-list="false" :on-success="uploadSuccess">
						<el-image class="avatar"
							:src="form.icon ? form.icon : require('../../assets/img/icon-11.png')" />
					</el-upload>

				</el-form-item>
				<el-form-item :label="$t('route.Item_name')">
					<el-input v-model="form.name" />
				</el-form-item>
				<el-form-item :label="$t('route.Payment_Number')">
					<el-input v-model="form.code" />
				</el-form-item>
				<!-- <el-form-item label="描述:">
					<el-input v-model="form.detail" />
				</el-form-item>
				<el-form-item label="颜色:">
					<input-tag :dynamicTags="form.colorList"></input-tag>
				</el-form-item>
				<el-form-item label="尺寸:">
					<el-checkbox-group v-model="form.sizeList">
						<el-checkbox label="S" />
						<el-checkbox label="M" />
						<el-checkbox label="L" />
						<el-checkbox label="XL" />
						<el-checkbox label="2XL" />
						<el-checkbox label="3XL" />
						<el-checkbox label="4XL" />
					</el-checkbox-group>
				</el-form-item> -->

				<el-form-item>
					<el-button @click='addClick' type="primary">{{ form.id ? $t('route.modify') : $t('route.Add') }}</el-button>
				</el-form-item>
			</el-form>
		</div>


	</div>
</template>

<script>
import http from "../../js/http/http.js";
import api from "../../js/http/api.js";
import CommonUtils from "../../js/common/common-utils.js";
import InputTag from '../../components/input-tag.vue'
import i18n from '../../i18n/index';
export default {
	components: {
		InputTag
	},
	data() {
		return {
			form: {
				code: null,
				name: null,
				icon: null,
				detail: null,
				colorList: [],
				sizeList: [],
			},
			uploadUrl: api.UPLOAD_FILE + '?type=5',

		};
	},
	methods: {
		uploadSuccess(response, file, fileList) {
			this.form.icon = response.data;
		},
		addClick() {
			if (CommonUtils.isEmpty(this.form.icon)) {
				this.$message.error(i18n.global.t('route.Picture_cannot_be_empty'));
				return;
			}
			if (CommonUtils.isEmpty(this.form.name)) {
				this.$message.error(i18n.global.t('route.The_account_name_cannot_be_empty'));
				return;
			}
			if (CommonUtils.isEmpty(this.form.code)) {
				this.$message.error(i18n.global.t('route.Item'));
				return;
			}
			// if (this.form.colorList.length == 0) {
			// 	this.$message.error('请选择颜色');
			// 	return;
			// }
			// if (this.form.sizeList.length == 0) {
			// 	this.$message.error('请选择尺寸');
			// 	return;
			// }
			http.post(api.ADD_STYLE, {
				styleId: this.form.id,
				name: this.form.name,
				code: this.form.code,
				adminId: this.$store.state.user.id,
				icon: this.form.icon,
				detail: this.form.detail,
				colorList: JSON.stringify(this.form.colorList),
				sizeList: JSON.stringify(this.form.sizeList),
			}, data => {
				var msg = this.form.id ? i18n.global.t('route.Modified_successfully') : i18n.global.t('route.Successfully_added');
				this.$message.success(msg);
				this.$router.go(-1);
			});
		}
	},
	created() {
		var style = CommonUtils.getParam(this, 'style', 'setStyle');
		console.log(style)
		if (style && style != "undefined") {
			this.form = JSON.parse(style);
		}
		if (this.form.id) {
			this.title = i18n.global.t('route.Edit_Style') ;
			this.form.colorList = JSON.parse(this.form.colorList);
			this.form.sizeList = JSON.parse(this.form.sizeList);
		}
	}
};
</script>
<style lang="scss" scoped>
.add-style {
	color: #444444;
	font-size: 18px;
	padding-right: 20px;
	height: calc(100vh - 100px);
	// overflow: scroll;
	scrollbar-width: none;
	/* firefox */
	-ms-overflow-style: none;
	/* IE 10+ */
	overflow-x: hidden;
	overflow-y: auto;

	.avatar {
		width: 130px;
		height: 130px;
	}

	>div:nth-of-type(1) {
		display: flex;
		flex-direction: row;
		align-items: center;
		margin-top: 20px;
		background-color: #ffffff;
		padding: 20px;
		border-radius: 5px;

		>label:nth-of-type(1) {
			font-weight: 600;
		}

		>div:nth-of-type(1) {
			width: 1px;
			background-color: #cccccc;
			height: 15px;
			margin: 0px 20px;
		}

		>button:nth-of-type(1) {
			background-image: url(../../assets/img/customer-1.png);
			background-repeat: no-repeat;
			background-size: 100% 100%;
			padding: 5px 10px;
			border: 0px;
			display: flex;
			color: #ffffff;
			flex-direction: row;
			align-items: center;
			font-weight: 800;

			>img {
				margin-right: 7px;
				width: 15px;
				height: 15px;
				content: url(../../assets/img/customer-2.png);
			}

		}
	}

	>div:nth-of-type(2) {
		display: flex;
		flex-direction: row;
		align-items: center;
		margin-top: 20px;
		background-color: #ffffff;
		padding: 20px;
		border-radius: 5px;

		.input {}

		.div-1 {
			display: flex;
			flex-direction: row;

			>label {
				margin-left: 10px;
				width: 200px;
			}
		}


	}





}
</style>
